import codegenApi from "@/api/declaration/codegenApi"
import httpRequest from "@/config/axios/httpRequest"
import { CodegenCreateListReqModel } from "@/models/gen/CodegenCreateListReqModel"
import { CodegenUpdateReqModel } from "@/models/gen/CodegenUpdateReqModel"

// 查询列表代码生成表定义
export const getCodegenTableList = (dataSourceConfigId: number) => {
  return httpRequest.get(codegenApi.GetCodegenTableList, { params: { dataSourceConfigId } })
}

// 查询列表代码生成表定义
export const getCodegenTablePage = (params: PageParam) => {
  return httpRequest.get(codegenApi.GetCodegenTablePage, { params })
}

// 查询详情代码生成表定义
export const getCodegenTable = (id: number) => {
  return httpRequest.get(codegenApi.GetCodegenTable, { params: { id } })
}

// 新增代码生成表定义
export const createCodegenTable = (data: CodegenCreateListReqModel) => {
  return httpRequest.post(codegenApi.CreateCodegenTable, data)
}

// 修改代码生成表定义
export const updateCodegenTable = (data: CodegenUpdateReqModel) => {
  return httpRequest.put(codegenApi.UpdateCodegenTable, data)
}

// 基于数据库的表结构，同步数据库的表和字段定义
export const syncCodegenFromDB = (id: number) => {
  return httpRequest.put(codegenApi.SyncCodegenFromDB, { id })
}

// 预览生成代码
export const previewCodegen = (id: number) => {
  return httpRequest.get(codegenApi.PreviewCodegen, { params: { id } })
}

// 下载生成代码
export const downloadCodegen = (id: number) => {
  return httpRequest.download(codegenApi.DownloadCodegen, { params: { id } })
}

// 获得表定义
export const getSchemaTableList = (params) => {
  return httpRequest.get(codegenApi.GetSchemaTableList, { params })
}

// 基于数据库的表结构，创建代码生成器的表定义
export const createCodegenList = (data) => {
  return httpRequest.post(codegenApi.CreateCodegenList, data)
}

// 删除代码生成表定义
export const deleteCodegenTable = (id: number) => {
  return httpRequest.delete(codegenApi.DeleteCodegenTable, { params: { id } })
}
